<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class adm_model extends CI_Model {
	public function __construct(){
		parent::__construct();
		$this->load->library('encrypt');
	}
	public function login_check($param){
		$this->db->where('jonu_admin_username', $param['adm_usr']);
		$this->db->where('jonu_admin_password', $this->encrypt->sha1($param['adm_pass']));
		$query = $this->db->get('jonu_admin');
		$result = $query->result_object();

		return $result[0];
	}

	public function getbyID($id){
		$this->db->where('jonu_admin_id', $id);
		$query = $this->db->get('jonu_admin');
		$result = $query->result_array();
		
		return $result;
	}

	public function update($param, $id){
		$this->db->where('jonu_admin_password', $this->encrypt->sha1($param['old_pass']));
		$this->db->where('jonu_admin_id', $id);
		$res_chk_adm = $this->db->count_all_results('jonu_admin');

		if($res_chk_adm == 1){
			if($param['adm_pass'] == ""){
				$data = array(
					'jonu_admin_fullname'	=> $param['adm_fullname'],
					'jonu_admin_email'		=> $param['adm_email']
					);
			}else{
				$data = array(
					'jonu_admin_fullname'	=> $param['adm_fullname'],
					'jonu_admin_password'	=> $this->encrypt->sha1($param['adm_pass']),
					'jonu_admin_email'		=> $param['adm_email']
					);
			}
			$this->db->where('jonu_admin_id', $id);
			$query = $this->db->update('jonu_admin', $data);

			return $query;
		}else{
			return  false;
		}
	}
}

/* End of file adm_model.php */
/* Location: ./application/models/adm_model.php */